﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Gebra
{
    public class Number : Operand
    {
        private readonly Complex _value;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_value">Number value.</param>
        public Number(Complex a_value)
        {
            _value = a_value;
        }

        /// <summary>
        /// Evaluate this operand.
        /// </summary>
        /// <returns>Result of evaluation.</returns>
        public override Operand Evaluate()
        {
            return this;
        }

        /// <summary>
        /// Number value.
        /// </summary>
        public Complex Value { get { return _value; } }

        /// <summary>
        /// Operator to cast a double value into a number instance.
        /// </summary>
        /// <param name="a_value">Double value.</param>
        /// <returns>Number instance.</returns>
        public static implicit operator Number(double a_value)
        {
            return new Number(a_value);
        }
        
        /// <summary>
        /// Operator to cast a complex value into a number instance.
        /// </summary>
        /// <param name="a_value">Complex value.</param>
        /// <returns>Number instance.</returns>
        public static implicit operator Number(Complex a_value)
        {
            return new Number(a_value);
        }

        /// <summary>
        /// Operator to cast a number instance into a double value.
        /// </summary>
        /// <param name="a_number">Number instance.</param>
        /// <returns>Double value.</returns>
        public static explicit operator double(Number a_number)
        {
            return a_number.Value.Real;
        }

        /// <summary>
        /// Opeartor to cast a number instance into a complex value.
        /// </summary>
        /// <param name="a_number">Number instance.</param>
        /// <returns>Complex value.</returns>
        public static explicit operator Complex(Number a_number)
        {
            return a_number.Value;
        }
    }
}
